package com.sinoeyes.system.service.impl;

import java.util.List;

import com.sinoeyes.common.core.page.RestPageResult;
import com.sinoeyes.common.vo.BaseVo;
import com.sinoeyes.system.filter.SysDictDataFilter;
import com.sinoeyes.system.mapper.SysDictDataMapper;
import com.sinoeyes.system.po.SysDictDataPo;
import com.sinoeyes.system.service.ISysDictDataService;
import com.sinoeyes.system.vo.SysDictDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 字典 业务层处理
 * 
 * @author ruoyi
 */
@Service
public class SysDictDataServiceImpl implements ISysDictDataService
{
    @Autowired
    private SysDictDataMapper dictDataMapper;

    /**
     * 根据条件分页查询字典数据
     * 
     * @param filter 字典数据信息
     * @return 字典数据集合信息
     */
    @Override
    public RestPageResult<SysDictDataVo> selectDictDataList(SysDictDataFilter filter) {

        filter.startPage();
        List<SysDictDataPo> sysDictDataPos = dictDataMapper.selectDictDataList(filter);
        RestPageResult pageResult = filter.getPageResult(sysDictDataPos);
        return BaseVo.copyPo2Vo(pageResult, SysDictDataVo.class);

    }

    /**
     * 根据字典类型查询字典数据
     * 
     * @param dictType 字典类型
     * @return 字典数据集合信息
     */
    @Override
    public List<SysDictDataVo> selectDictDataByType(String dictType)
    {
        return BaseVo.copyPo2Vo(dictDataMapper.selectDictDataByType(dictType), SysDictDataVo.class);
    }

    /**
     * 根据字典类型和字典键值查询字典数据信息
     * 
     * @param dictType 字典类型
     * @param dictValue 字典键值
     * @return 字典标签
     */
    @Override
    public String selectDictLabel(String dictType, String dictValue)
    {
        return dictDataMapper.selectDictLabel(dictType, dictValue);
    }

    /**
     * 根据字典数据ID查询信息
     * 
     * @param dictCode 字典数据ID
     * @return 字典数据
     */
    @Override
    public SysDictDataVo selectDictDataById(Long dictCode)
    {
        return BaseVo.copyPo2Vo(dictDataMapper.selectDictDataById(dictCode), SysDictDataVo.class);
    }

    /**
     * 通过字典ID删除字典数据信息
     * 
     * @param dictCode 字典数据ID
     * @return 结果
     */
    @Override
    public int deleteDictDataById(Long dictCode)
    {
        return dictDataMapper.deleteDictDataById(dictCode);
    }

    /**
     * 新增保存字典数据信息
     * 
     * @param dictDataVo 字典数据信息
     * @return 结果
     */
    @Override
    public int insertDictData(SysDictDataVo dictDataVo)
    {
        return dictDataMapper.insertDictData(BaseVo.copyVo2Po(dictDataVo, SysDictDataPo.class));
    }

    /**
     * 修改保存字典数据信息
     * 
     * @param dictDataVo 字典数据信息
     * @return 结果
     */
    @Override
    public int updateDictData(SysDictDataVo dictDataVo)
    {
        return dictDataMapper.updateDictData(BaseVo.copyVo2Po(dictDataVo, SysDictDataPo.class));
    }
}
